<?php 
$lang="KR";
$company="elisoft";
$id_employee="none";
$id_approvedoc="none";
$idgroupapprove="1351215692633";
$id_employee_last="";
$co=0;

$database = 'elihan';
//echo $database;

if (empty($lang) || $lang == "EN") {
	$value = "value/value_en.php";
} else if($lang == "VN") {
	$value = "value/value_vn.php";
}
else {
	$value = "value/value_kr.php";
}
include($value);

try {
	ini_set('display_errors', 0);
	$connection = mysql_connect("1.234.53.52", "cam", "5678" ) ;
	if(!$connection){
		echo "khong connect duoc<br>";		
	}		
	if(!mysql_select_db($database,$connection)){	
		echo "khong select duoc db<br>";	
	}
	if(!mysql_query("SET CHARACTER SET 'utf8'", $connection)){	
		echo "khong set character<br>";	
	}
} catch (Exception $e) {
	echo 'Loi';	
}

/*
require_once('class.phpmailer.php');

//Khá»Ÿi táº¡o Ä‘á»‘i tÆ°á»£ng
$mail = new PHPMailer();

$mail->IsSMTP(); // Gá»�i Ä‘áº¿n class xá»­ lÃ½ SMTP
//$mail->Host       = "mail.zend.vn"; // tÃªn SMTP server
$mail->SMTPDebug  = 2;                    // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // Sá»­ dá»¥ng Ä‘Äƒng nháº­p vÃ o account
$mail->SMTPSecure = "ssl";
$mail->Host       = "smtp.gmail.com";     // Thiáº¿t láº­p thÃ´ng tin cá»§a SMPT
$mail->Port       = 465;                     // Thiáº¿t láº­p cá»•ng gá»­i email cá»§a mÃ¡y
$mail->Username   = "elisoftmailserver@gmail.com"; // SMTP account username
$mail->Password   = "1234567892727";         // SMTP account password

//Thiet lap thong tin nguoi gui va email nguoi gui
$mail->SetFrom('elisoftmailserver@gmail.com',$company);

//Thiáº¿t láº­p thÃ´ng tin ngÆ°á»�i nháº­n



//Thiáº¿t láº­p email nháº­n email há»“i Ä‘Ã¡p
//náº¿u ngÆ°á»�i nháº­n nháº¥n nÃºt Reply
$mail->AddAddress("orchipro@gmail.com", "orchipro");
$mail->AddAddress("klkim169@gmail.com", "klkim");
$mail->AddAddress("kisadlu@gmail.com", "kisadlu");
//$mail1="klkim169@gmail.com";
//$mail2="kisadlu@gmail.com";
$mail->Subject    =  $company." - ".$l_listassets." - (".date("Y-m-d").")";
*/
$result=mysql_query("SELECT e.IDEmployee,e.FullName,e.Email FROM list_sendmailassets l,employee e WHERE  e.IDEmployee=l.employee_id GROUP BY l.employee_id");

while ($r=mysql_fetch_array($result)){
	echo $r['FullName'].'-'.$r['Email']."<br>";
}

$assets=array();
$result=mysql_query("SELECT g.`name` as nameg,b.* ,
							(SELECT count(*) FROM assets c WHERE c.`group`=b.`group` AND c.type=b.type ) as counttype ,
							(SELECT SUM(c.count+c.notuse+c.stock) FROM assets c WHERE c.`group`=b.`group` ) as sumassets ,
							(SELECT e.FullName FROM employee e WHERE e.IDEmployee=b.creater) as FullName
FROM group_assets g LEFT JOIN (SELECT a.*,t.`name` as namet FROM assets a , type_assets t WHERE a.type=t.id ) b  ON b.`group`=g.id 
ORDER BY g.`name`,b.namet,b.`name`;");
while ($row=mysql_fetch_array($result)){
	$assets[$row['nameg']][]=array($row['name'],$row['count'],$row['notuse'],$row['stock'],$row['namet'],$row['note'],$row['counttype'],$row['FullName'],$row['datetime'],$row['type'],$row['group'],$row['sumassets']);
}
$body.='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
				<html xmlns="http://www.w3.org/1999/xhtml">
				<head>
				<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
				<title>Untitled Document</title>
				</head>
				
				<body>
				<table class="ftable" width="100%" cellspacing="1" cellpadding="0" border="0">
				<tbody>
				 <tr height="35px">
				 	<th style="min-width: 100px;background: #4f81bd;height: 30px;color: white;font-size: 14px;font-weight: bold;">'.$l_groupassets.'</th>
	                <th style="min-width: 100px;background: #4f81bd;height: 30px;color: white;font-size: 14px;font-weight: bold;">'.$l_typeassets.'</th>
	                <th style="min-width: 30px;background: #4f81bd;height: 30px;color: white;font-size: 14px;font-weight: bold;">'.$l_no.'</th>
	                <th style="min-width: 200px;background: #4f81bd;height: 30px;color: white;font-size: 14px;font-weight: bold;">'.$l_nameassets.'</th>
	                <th style="min-width: 60px;background: #4f81bd;height: 30px;color: white;font-size: 14px;font-weight: bold;">'.$l_using.'</th>
	                <th style="min-width: 60px;background: #4f81bd;height: 30px;color: white;font-size: 14px;font-weight: bold;">'.$l_notused.'</th>
	                <th style="min-width: 60px;background: #4f81bd;height: 30px;color: white;font-size: 14px;font-weight: bold;">'.$l_stock.'</th>
	                <th style="min-width: 60px;background: #4f81bd;height: 30px;color: white;font-size: 14px;font-weight: bold;">'.$l_total.'</th>
	                <th style="min-width: 100px;background: #4f81bd;height: 30px;color: white;font-size: 14px;font-weight: bold;">'.$l_note.'</th>
	                <th style="min-width: 100px;background: #4f81bd;height: 30px;color: white;font-size: 14px;font-weight: bold;">'.$l_author.'</th>
	                <th style="min-width: 100px;background: #4f81bd;height: 30px;color: white;font-size: 14px;font-weight: bold;">'.$l_time.'</th>
	                
	            </tr>';
				$i=0;
				foreach ($assets as $value => $giatri) {
					
				
					if($giatri[0][0]=="")
						$body.='<tr style="background: #90BEE8;" height="35px">
				                <td style=" padding-left: 10px;font-size: 14px;text-align: left;" colspan="11">'.$value.'(0)</td></tr>';
					else{
						
						$body.='<tr style="background: #90BEE8;" height="35px">
					                <td style=" vertical-align: top;padding-top: 10px; padding-left: 10px;font-size: 14px;text-align: left;" rowspan="'.count($giatri).'">'.$value.'('.$giatri[0][11].')</td>';
						$j=0;
						$temp="";
						foreach ($giatri as $value1 => $giatri1) {
							$i++;
							$j++;
							if($j!=1)
								$body.='	<tr style="background: #90BEE8;" height="35px">';
								if($temp!=$giatri1[4]){
										
										$result=mysql_query("SELECT SUM(a.count) as sumcount,SUM(a.notuse) as sumnotuse,SUM(a.stock) as sumstock FROM assets a WHERE a.type='".$giatri1[9]."' AND a.`group`='".$giatri1[10]."';");
				            			$temp=	$giatri[5];
				            			$r=mysql_fetch_assoc($result);
				            			$tong=$r['sumcount']+$r['sumnotuse']+$r['sumstock'];
										
										$body.= '  <td style="vertical-align: top;padding-top: 8px;text-align: left;font-size: 14px;padding-left: 10px;" rowspan="'.$giatri1[6].'">'.$giatri1[4].'(<span style="font-weight:bold">'.$tong.'</span>)</td>';
										$temp=$giatri1[4];
									}
							$body.='	
											<td style="font-size: 14px;text-align: center;">'.$i.'</td>
							                <td style="text-align: left;font-size: 14px;padding-left: 10px;">'.$giatri1[0].'</td>
							                <td style="text-align:center;font-size: 14px;">'.$giatri1[1].'</td>
							                <td style="text-align:center;font-size: 14px;">'.$giatri1[2].'</td>
							                <td style="text-align:center;font-size: 14px;">'.$giatri1[3].'</td>
							                <td style="text-align:center;font-size: 14px;font-weight:bold">'.($giatri1[1]+$giatri1[2]+$giatri1[3]).'</td>
							                <td style="text-align:center;font-size: 14px;">'.$giatri1[5].'</td>
							                <td style="text-align:center;font-size: 14px;">'.$giatri1[7].'</td>
							                <td style="text-align:center;font-size: 14px;">'.$giatri1[8].'</td>
							                </tr>';
						}
					
					}
					/*$result1=mysql_query("SELECT a.* FROM assets a WHERE a.type=".$row['id']." ORDER BY a.count,a.`name`;");
					while ($row1=mysql_fetch_array($result1)){
						
					}*/
				}
				
				$body.='</tbody>
				</table>
				</body>
				</html>';
	echo $body;			           

/*
//Thiáº¿t láº­p Ä‘á»‹nh dáº¡ng font chá»¯
$mail->CharSet = "utf-8";
$mail->IsHTML(true);

$mail->Body = $body;
//$mail->AltBody=$dtitle;

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
 echo "Sent Mail Assets ";
}*/
			


	


mysql_close($connection);
?>